package com.zide.system.controller.monitor;

import com.zide.common.annotation.Log;
import com.zide.common.core.domain.CommonResult;
import com.zide.common.core.domain.PageResult;
import com.zide.common.enums.BusinessType;
import com.zide.common.utils.poi.ExcelUtil;
import com.zide.common.core.domain.SysLogininfor;
import com.zide.framework.web.domain.loginfor.SysLogininforSearchVO;
import com.zide.framework.web.service.ISysLogininforService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zide.common.core.domain.CommonResult.getResult;
import static com.zide.common.core.domain.CommonResult.success;

/**
 * 系统访问记录
 *
 * @author zide
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController {
    @Autowired
    private ISysLogininforService logininforService;

    @GetMapping("/list")
    public CommonResult list(SysLogininforSearchVO searchVO) {

        PageResult<SysLogininfor> list = logininforService.selectLogininforPage(searchVO);
        return success(list);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLogininfor logininfor) {
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
        util.exportExcel(response, list, "登录日志");
    }

    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public CommonResult remove(@PathVariable Long[] infoIds) {
        return getResult(logininforService.deleteLogininforByIds(infoIds));
    }

    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public CommonResult clean() {
        logininforService.cleanLogininfor();
        return success();
    }

    @Log(title = "账户解锁", businessType = BusinessType.OTHER)
    @GetMapping("/unlock/{username}")
    public CommonResult unlock(@PathVariable("username") String username) {
        return success();
    }
}
